package org.accp.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.accp.dao.HisroleDao;
import org.accp.dao.IllnessDao;
import org.accp.pojo.Hisrole;
import org.accp.pojo.Illness;
import org.accp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@RequestMapping("/ill")
@Controller
@CrossOrigin("*")

public class IllnessController {
    @Autowired
    private IllnessDao illnessDao;

    @RequestMapping("/search")
    @ResponseBody
    public List<Illness> search() throws Exception {
        return illnessDao.getAll();
    }

    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<Illness>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, Illness condition) throws Exception {
        Page<Illness> pager = PageHelper.startPage(page, limit);
        List<Illness> list = illnessDao.getConditionList(condition);
        return new ResponseResult<>(pager.getTotal(), list);
    }
}


